package com.djinfo.work.controller;

import com.djinfo.work.common.bean.AjaxJson;
import com.djinfo.work.common.util.StringUtil;
import com.djinfo.work.entity.TbSysMenu;
import com.djinfo.work.service.MenuService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author ming 描述： 菜单管理Controller
 */
@Controller
@RequestMapping("/menu")
public class MenuController {
	private static final Log log = LogFactory.getLog(MenuController.class);
	/**
	 * 自动注入
	 */
	@Autowired
	private com.djinfo.work.service.MenuService menuService;


	/**
	 * 菜单信息主表实体类
	 */
	private TbSysMenu menu;
	/**
	 * 列表
	 */
	@RequestMapping("/list.do")
	@ResponseBody
	public AjaxJson list(TbSysMenu menu, Integer pagenum, Integer pagesize){
		AjaxJson ajaxJson = menuService.list(menu,pagenum,pagesize);
		return ajaxJson;
	}


	/**
	 * 获取对象信息
	 */
	@RequestMapping("/info.do")
	public ModelAndView info(TbSysMenu menu){
		TbSysMenu res = menuService.selectOne(menu);
		return new ModelAndView("menu/edit.html","menu",res);
	}
	/**
	 * 添加跳转
	 */
	@RequestMapping("/add.do")
	public ModelAndView add(){
		TbSysMenu menu=new TbSysMenu();
		return new ModelAndView("menu/edit.html","menu",menu);
	}
	/**
	 * 获取level级菜单列表
	 */
	@RequestMapping("/getLevel1MenuList.do")
	@ResponseBody
	public AjaxJson getLevel1MenuList(TbSysMenu menu){
		AjaxJson ajaxJson = menuService.getLevel1MenuList(menu);
		return ajaxJson;
	}


	/**
	 * 修改
	 */
	@RequestMapping("/saveOrUpdate.do")
	@ResponseBody
	public AjaxJson saveOrUpdate(TbSysMenu menu, HttpServletRequest request){
		AjaxJson ajaxJson = menuService.saveOrUpdate(menu,request);
		return ajaxJson;
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete.do")
	@ResponseBody
	public AjaxJson delete(TbSysMenu menu){

		AjaxJson ajaxJson = menuService.delete(menu);
		return ajaxJson;
	}


}
